package com.registry.client.springevent;

import com.registry.client.service.RegistryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

/**
 * 服务关闭时，要向注册中心注销服务，这里是停止服务时的事件驱动
 */
public class SpringCloseEvent  implements ApplicationListener<ContextClosedEvent> {

    @Autowired
    private RegistryService registryService;
    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        registryService.remove();
    }
}
